{% extends '::backend.html.twig' %}
{% block contenido %}
{%if esEditor is null%}
{% set esEditor = false%}
{%endif%} 
{% if is_granted("ROLE_EDITAR_INSCRIPTO") %}
{% set esEditor = true%}

{%endif%}

{% include 'BackendBundle:Concurso:flashAlerts.html.twig'%}
<div class="btn-group">
    <a class="btn" href="{{ path('concurso') }}">
        <i class="icon-arrow-left"></i> Volver </a>   
    <a class="btn  btn-success" href="{{ path('concurso_new') }}">
        <i class="icon-plus" ></i>Agregar Concurso
    </a>
</div>



     {% if entities is not empty %}


<fieldset>

    <legend>{{title |default('Inscriptos')}}</legend>

    <div class="row-fluid show-grid">
        <div class="span12">

            <table id="table-inscriptos" class="table table-striped table-bordered table-striped table-hover">
                <thead>
                    <tr>
                        <th>Dni</th>
                        <th>Apellido</th>
                        <th>Nombre</th>
                        <th>Email</th>
                        <th>Tel&eacute;fono</th>
                        <th>Direcci&oacute;n</th>
                        <th>C&oacute;digo Postal</th>
                        <th>Fecha Notificaci&oacute;n</th>
                    </tr>
                </thead>
                <tbody id="tbody-inscriptos">
    {% for inscripto in entities %}
                        <tr id="inscripto-{{inscripto.persona.id}}">
                            <td class="with-link"><a href="{{ path('persona_show', { 'id': inscripto.persona.id }) }}">{{ inscripto.persona.dni }}</a></td>
                            <td>{{ inscripto.persona.apellido }}</td>
                            <td>{{ inscripto.persona.nombre  }}</td>               
                            <td>{{ inscripto.persona.email }}</td>
                            <td>{{ inscripto.persona.telefono }}</td>
                            <td>{{ inscripto.persona.direccion }}</td>
                            <td>{{ inscripto.persona.codigopostal }}</td>                        
                            {%if inscripto.fechaNotificacion is not null%}
                            <td>{{ inscripto.fechaNotificacion | date('d/m/Y') }}</td>
                            {%else%}
                            <td>----</td>
                            {%endif%}

                            <td>
                                     {%if permisos.inscriptos and estaImpugnado is sameas(false) and estaCerrado is sameas(false)%}
                                    <div class="btn-group">
                                        <a  class="btn btn-info dropdown-toggle" data-toggle="dropdown" href="#">
                                            <i class=" icon-plus"> </i> Acciones
                                            <span class="caret"></span>
                                        </a>
                                        <ul class="dropdown-menu">
                                            <li>
                                                <a class="edit" href="{{ path('inscripto_edit', { 'id': inscripto.persona.id }) }}">
                                                    <i class="icon-edit"></i> Editar 
                                                </a>
                                            </li>
                                            <li> <a data-body="tbody-inscriptos" data-table="table-inscriptos" data-row="inscripto-{{inscripto.persona.id}}" class="unset" href="{{ path('concurso_unset_inscripto', { 'id': inscripto.id }) }}">  <i class="icon-trash"></i> Eliminar</a>
                                            </li>


                                            </li>
                                       {%endif%}
                                        </ul>
                                    </div>                
                                </td>

                            </tr>

    {% endfor %}
                        </tbody>
                    </table>
                </div>

            </div>

        </fieldset>        

    {{ simple_paginator_render(rutaPaginador, null, {
    'container_class':    'paginador',
    'routeParams' : {'id' : concurso},
    'previousPageText':   'Anterior',

    'nextPageText':       'Siguiente',

    'currentClass':       'actual',

    'firstPageText':      'Primera',
    'firstEnabledClass':  'oculto',
    'firstDisabledClass': 'oculto',

    'lastPageText':       'Última',
    'lastEnabledClass':   'oculto',
    'lastDisabledClass':  'oculto',
}) }}




        <div id="confirmation-dialog" style="display:none">

            <div class="alert alert-error">
                <strong>Se va a borrar!</strong> el dato, está seguro?
            </div>
        </div>
    {% else %}

        <legend> {{title |default('Inscriptos')}}</legend>
      {% endif %}



        <div id="target-dialog" style="display: none"></div>
{% endblock %}

  {% block documentReadyJavascript %} 
     {%if esEditor %}
        <script type="text/javascript">
        $(function(){
            var spin_opt = {
    lines: 9, 
    length: 3, 
    width: 2, 
    radius: 4, 
    corners: 1, 
    rotate: 0, 
    color: '#000', 
    speed: 0.9, 
    trail: 60, 
    shadow: false, 
    hwaccel: false,
    className: 'spinner', 
    zIndex: 2e9, 
    top: 'auto', 
    left: 'auto' 
    };
                        
        $(".desplegable").on('click', function(e){
            e.preventDefault();
            var $div = $(this).parent().parent().find('div.oculto')
      
          
              if( !$div.is(':visible')){
          $(this).find('i').removeClass('icon-plus');    
          $(this).find('i').addClass('icon-minus');    
          }else{
          $(this).find('i').removeClass('icon-minus');    
          $(this).find('i').addClass('icon-plus');    
      }
          $div.toggle( 'blind', {}, 500 );
         
    });
    $(".unset").on('click',function(e){  
        e.preventDefault();
        var $this =  $(this);
        var to_go = $this.attr('href');
                   
        var $row = $("#"+$this.attr('data-row'));
        var $table = $("#"+$this.attr('data-table')); 
        var $tbody = $("#"+$this.attr('data-body'));
    
    
         $("#confirmation-dialog").dialog({
                                        resizable: false,
                                        height:180,
                                        width:'auto',
                                        modal: true,
                                        title:"Alerta!",
                                        buttons: {
                                            "Eliminar": function() {
                                                $.ajax({
        url:to_go,
        type:'POST',
                 
        beforeSend:function(){
            $this.spin(spin_opt);
    },
        complete:function(data){
             $this.spin(false);
           var result =$.evalJSON(data.responseText);
           if(result.status){
               console.log("$row.",$row);              
               $row.fadeOut(400, function(){
                          $(this).remove();
                      if($tbody.children().size()==0){
                          $table.hide();
                          $(".paginador").remove();
                      }
                      });     
                       $("#confirmation-dialog").dialog("close");
           }else{
               alert(result.mensaje);
           }
                       
    }
                
    })//fin ajax
            
                                            },
                                            Cancelar: function() {
                                                $(this).dialog( "close" );
                                            }
                                        }
                          });
    
    
    
    
    
    
    
    
    
    
    
    
    
    
      
                
    });//fin click
            
            
            
    /*edicion de entiddes*/
    $(".edit").on('click',function(e){  
        e.preventDefault();
        var $this =  $(this);
        var $target_dialog = $("#target-dialog");
        var to_go = $this.attr('href');
        var $row = $("#"+$this.attr('data-row'));
        var $table = $("#"+$this.attr('data-table')); ;
        var $tbody = $("#"+$this.attr('data-body'));;
        $.ajax({
        url:to_go,
        type:'POST',
        beforeSend:function(){
            $this.spin(spin_opt);
    },
        complete:function(data){
             $this.spin(false);
             var result = data.responseText;
                         
             $target_dialog.html(result).dialog({
                             
    maxWidth:750,      
    width: 'auto',
    modal: true,
    position: "center" 
     }).show('slow');
                                           
    $.each($('#target-dialog ').find('input.span12, textarea.span12'), function(i,x){ $(x).removeClass('span12').addClass('span3')})
    }
                
    })//fin ajax
                   
                
    });//fin click
    /*Fin edicion de entdades */
    })
            </script>
{%endif%}
     {% endblock documentReadyJavascript %}
